﻿using System;
using System.Windows.Data;
using System.Collections.ObjectModel;
using PersonaLibrary.Data;

namespace PersonaLibrary.Converters
{
    /// <summary>
    /// Gets the appointments for the specified date.
    /// </summary>
	[ValueConversion(typeof(ObservableCollection<Employee>), typeof(ObservableCollection<Employee>))]
    public class AppointmentsConverter : IMultiValueConverter
    {
        #region IMultiValueConverter Members

        public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
			if (values[1] == null)
				return null;

            DateTime date = (DateTime)values[1];

        	int count = 0;

			foreach (Employee appointment in (ObservableCollection<Employee>)values[0])
            {
				if (appointment.Birthday.HasValue && appointment.Birthday.Value.Date.Day == date.Day && appointment.Birthday.Value.Date.Month == date.Month
					|| (appointment.InexactBirthday != null && appointment.InexactBirthday.Contains(string.Format("{0}.{1}", date.Day, date.Month))))
				{
					count++;
				}
            }

			if(count != 0)
				return count;

        	return null;
        }

        public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }

        #endregion
    }
}
